package com.xx.controller;

import com.xx.entity.User;
import com.xx.util.DateUtil;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;


//@Controller
//@ResponseBody
@RestController
@RequestMapping("/user")
public class UserController {
    //新增用户
    @PostMapping("/savaUser")
    public String savaUser(@RequestBody User user){
        System.out.println("接收新增用户信息===>"+user);

        return "新增用户!";
    }


    //修改用户信息
    @PostMapping("/updateUser")
    public String updateUser(@RequestBody User user){
        System.out.println("接收修改用户信息===>"+user);
        return "修改用户!";
    }
    //删除用户信息
    @GetMapping("/delUser")
    public String delUser(Integer userId){
        System.out.println("接收修改用户信息===>"+userId);
        return "删除用户信息!";
    }
    //获取用户列表
    @GetMapping("getUsers")
    public List<User> getUsers(String name,String tel) throws ParseException {
        List<User> users = new ArrayList<>();
        User user = new User();
        user.setUserId(1);
        user.setUserName("张三");
        user.setSex("男");
        user.setPassword("123");
        user.setTel("15974139564");
        user.setRegisterDate(DateUtil.stringToDate("2024-10-09","yyy-MM-dd"));
        users.add(user);

        User user1 = new User();
        user1.setUserId(1);
        user1.setUserName("法外狂徒");
        user1.setSex("男");
        user1.setPassword("123");
        user1.setTel("15974139564");
        user1.setRegisterDate(DateUtil.stringToDate("2024-10-09","yyy-MM-dd"));
        users.add(user1);

        return users;
    }
    //获取指定用用户详情
    @GetMapping("getUser")
    public  User getUser(Integer userId) throws ParseException {
        User user = new User();
        user.setUserId(1);
        user.setUserName("小南");
        user.setSex("女");
        user.setPassword("123");
        user.setTel("123123123");
        user.setRegisterDate(DateUtil.stringToDate("2025-10-09", "yyyy-mm-dd"));
        return user;
    }
}
